﻿#ifndef DAMETHODEDITORGRAPHICSSCENE_H
#define DAMETHODEDITORGRAPHICSSCENE_H
#include <QGraphicsScene>
#include <QHash>
#include <QUndoStack>
#include "DADataWorkFlow.h"
#include "DANodeGraphicsScene.h"
#include "DAAbstractNodeGraphicsItem.h"
class QGraphicsSceneWheelEvent;
namespace DA
{
class DAGraphicsResizeablePixmapItem;
class DAWorkFlowGraphicsScene : public DANodeGraphicsScene
{
    Q_OBJECT
public:
    DAWorkFlowGraphicsScene(QObject* parent = 0);

    //添加一个背景图,如果多次调用，此函数返回的QGraphicsPixmapItem* 是一样的，也就是只会创建一个QGraphicsPixmapItem*
    DAGraphicsResizeablePixmapItem* setBackgroundPixmap(const QPixmap& pixmap);
    //获取背景图item，如果没有设置返回一个nullptr
    DAGraphicsResizeablePixmapItem* getBackgroundPixmapItem(bool autoCreate = true);
    //设置背景item，如果外部调用getBackgroundPixmapItem并删除，需要通过此函数把保存的item设置为null
    void setBackgroundPixmapItem(DAGraphicsResizeablePixmapItem* item);
    //设置开始插入文本框，此时鼠标点击点作为文本框插入点
    void startCreateTextItemByMouse();
    //停止插入文本框
    void stopCreateTextItemByMouse();
    //判断是否处于创建textitem模式
    bool isCreatingTextItemByMouse() const;
    //文字加粗
    void setTextBold(bool on);
    //文字斜体
    void setTextItalic(bool on);
    //设置文字颜色
    void setTextColor(const QColor& color);
    //设置字体样式
    void setTextFamily(const QString& family);
    //设置字体大小
    void setTextSize(const int size);
    //允许item跟随背景图移动
    void enableItemMoveWithBackground(bool on);
    //是否item跟随背景图移动
    bool isEnableItemMoveWithBackground() const;

protected:
    DAGraphicsResizeablePixmapItem* ensureGetBackgroundPixmapItem();

protected:
    virtual void dragEnterEvent(QGraphicsSceneDragDropEvent* event) override;
    virtual void dragMoveEvent(QGraphicsSceneDragDropEvent* event) override;
    virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent* event) override;
    virtual void dropEvent(QGraphicsSceneDragDropEvent* event) override;

    //鼠标点击事件
    virtual void mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
    //鼠标释放
    virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
signals:
    /**
     * @brief 用户创建了文本框发射的信号
     */
    void createdTextItem();
private slots:
#if DA_USE_QGRAPHICSOBJECT
    void backgroundPixmapItemXChanged();
    void backgroundPixmapItemYChanged();
    void backgroundPixmapItemBodyItemBodySizeChanged(const QSizeF& oldsize, const QSizeF& newsize);
#endif
private:
    DAGraphicsResizeablePixmapItem* _backgroundPixmapItem;
    bool m_addTextFlag;                   //插入文本框标志位
    bool m_enableItemMoveWithBackground;  ///< 允许item跟随背景图移动
    QColor m_textColor;
    QFont m_currentFont;
    QPointF _backgroundPixmapItemLastPos;  //背景图移动前的坐标
    QPointF _pixmapResizeLastPos;          //背景图拖动缩放前的坐标
};
}  // end of namespace DA
#endif  // GGRAPHICSSCENE_H
